package popple.display
{
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.TimerEvent;
	import flash.utils.Dictionary;
	
	import popple.core.PP2D;
	import popple.core.RenderHelper;
	/**
	 *基类 
	 * @author popplecui
	 * 
	 */
	public class BaseObject extends EventDispatcher
	{
		public var depth:int;
		public var name:String;
		public var id:uint;
		protected var mPP2D:PP2D;
		protected var mData:*;
		
		
		protected var mHandleMap:Object={};
		//视口比例
		protected var mScale:Number;
		protected var mRenderHelper:RenderHelper;
		
		public function BaseObject()
		{
			mRenderHelper=RenderHelper.getInstance();
			
		}
		
		public function set data(value:*):void
		{
			mData=value;
		}
		public function get data():*
		{
			return mData;
		}
		
		public function addEventHandle(name:String,value:Function):void
		{
			if(mHandleMap[name]==null)mHandleMap[name]=new Dictionary;
			if(mHandleMap[name][value]==null)
			{
				mHandleMap[name][value]=value;
			}
		}
		public function removeEventHandle(name:String,value:Function):void
		{
			if(mHandleMap[name]!=null)
			{
				mHandleMap[name][value]!=null?delete mHandleMap[name][value]:value;
			}
		}
		public function render():void
		{
			executeHandle("enterFrame");
		}
		protected function executeHandle(name:String):void
		{
			var event:Dictionary,handle:Function;
			if(mHandleMap[name]!=null)
			{
				event=mHandleMap[name];
				for each(handle in event)
				{
					handle(this as DisplayObject);
				}
			}
		}
		public function removeListener(value:Function):void
		{
			if(mHandleMap[value]!=null)
			{
				mHandleMap[value]=null;
				delete mHandleMap[value];
			}
		}
	}
}